/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.univcasa.biz.impl;

import com.univcasa.biz.MoodleManager;
import com.univcasa.db.model.CompteEtudiant;
import com.univcasa.db.model.ComptePersonnel;
import com.univcasa.db.model.Criteres;
import com.univcasa.db.model.MoodleFlag;
import com.univcasa.managing.ComptesStudentsManager;
import com.univcasa.managing.MoodleDBManager;
import com.univcasa.managing.impl.ComptesStudentsManagerImpl;
import com.univcasa.managing.impl.MoodleDBManagerImpl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author Work
 */
public class MoodleManagerImpl implements MoodleManager{

    private MoodleDBManager manager ;
    private ComptesStudentsManager stdManager;

    public MoodleManagerImpl() {
        manager = new MoodleDBManagerImpl();
        stdManager = new ComptesStudentsManagerImpl();
    }

    public void addStds2Moodle(List lista) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void addPers2Moodle(List lista) {
        throw new UnsupportedOperationException("Not supported yet.");
    }   

    public void addStds2Moodle(CompteEtudiant std) {
        manager.addStd2MoodleSync(std);
    }

    public void addPers2Moodle(ComptePersonnel pers) {
        manager.addPers2MoodleSync(pers);
    }

    public List getListStds2Add(Criteres crits) {
        crits.addCritere("type", "std");
        List listMoodle = manager.getListComptesMoodle(crits);
        List listStd = stdManager.getApogeeComptesStudents(crits);
        List resultat = new ArrayList();


        for(Iterator itr = listMoodle.iterator();itr.hasNext();){
            MoodleFlag flag = (MoodleFlag) itr.next();
            if ( listStd.contains( flag.getId() )){
            resultat.add( stdManager.getCompteEtudiantByApogee( flag.getId() ));
            }
        }
        
        return resultat;
    }

    public List getListPers2Add(Criteres crits) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void deleteExistingMoodleStds() {
        Criteres crits = new Criteres();
        crits.addCritere("type", "std");
        List allStds = manager.getListComptesMoodle( crits );
        for(Iterator itr = allStds.iterator(); itr.hasNext();){
            MoodleFlag flag = (MoodleFlag) itr.next();
            String apogee = flag.getId();
            if (manager.isExistInMoodle( stdManager.getCompteEtudiantByApogee(apogee).getUid() )){
            manager.deleteStdFromMoodleSync(apogee);
            }
        }
    }
}
